<?php
session_start();

include_once("../lib/functions.php");
getProjectRootPath();
//die("DOC-ROOT: ".$_SERVER['DOCUMENT_ROOT']);
require_once($_SERVER['DOCUMENT_ROOT']."/updates/PostActions.php");
require_once($_SERVER['DOCUMENT_ROOT']."/updates/ReadNewsFeed.php");
require_once($_SERVER['DOCUMENT_ROOT']."/updates/ReadNotifications.php");
require_once($_SERVER['DOCUMENT_ROOT']."/includes/common_snippets.php");

//echo "ajaxHtml";
$actionType="";
if(isset($_POST["actiontype"]) && trim($_POST["actiontype"])!=""){
    //mean there is some action to perform
    $actionType=trim($_POST["actiontype"]);
    $loggedInId=0;
    try {
            $oLog= new Log();
        //try to read all psted values
            if (isset($_SESSION["Allyfolio_User_ID"]) && !empty($_SESSION["Allyfolio_User_ID"])) {
                $loggedInId = trim($_SESSION["Allyfolio_User_ID"]);
            }
                        
        if($loggedInId >0 ){ 
			//echo "<pre>"."actiontype: ".$actionType."</pre>";           
            switch($actionType){
            	case "show_clusters_friends_for_popup": //like 
				 	              
                    try {
                    	$clusterid=0;
                    	if (isset($_POST["clusterid"]) && !empty($_POST["clusterid"])) {
			                $clusterid = trim($_POST["clusterid"]);
			            }
			           
			            if(is_numeric($clusterid) && $clusterid>0){
							$oDropfilters= new CGetFilters();
	                        $clusterFriendsList=$oDropfilters->getClusterFriends($loggedInId,$clusterid,1);
	                        
	                        $friendsJSON[]= new DetailJson();
	                        $friendsCount=0;
	                        
	                        $clusterStr='';
	                        $jsonFriendInfo="";
	                        $myclusterFriendcount=0;
                            if(count($clusterFriendsList)>0){
	                           $oNotification=new Notifications();
                                foreach($clusterFriendsList as $myclusterFriendcount){										
                                	$UserDetail=$oNotification->getUserDetails($myclusterFriendcount["User_ID"]);
		                            if(is_array($UserDetail) && count($UserDetail)>0){
		                                //echo "<br>userid: ".$newNotification["User_ID"];
		                                //print_r($UserDetail);
		                                //die();
		                                $friendsJSON[$friendsCount]->actionByUserId=$UserDetail["uid"];
		                                $friendsJSON[$friendsCount]->actionByUserName=$UserDetail["uname"];
		                                $friendsJSON[$friendsCount]->actionByUserProfilePicpath=$UserDetail["picpath"];
		                                $friendsJSON[$friendsCount]->actionByUserLink=$UserDetail["plink"];
		                                $friendsJSON[$friendsCount]->actionByUserIsCelibrity=$UserDetail["Is_Celebrity"];
		                                $friendsCount++;
		                            }
		                            
                                	if(count($friendsJSON)>0 && $friendsCount>0){
							            //means has some post details
							           $jsonFriendInfo= $oNotification->getUserDetailsJSON($friendsJSON,false);
							        }
                                }
                                echo $jsonFriendInfo;
                           }
                           else{
                                echo "No friends added";    
                           }
	                        
						}
						else{
							echo "Invalid Cluster";							
						}
                       
                    }
                    catch(Exception $ex){
                        $oLog->writeException('ajax/getAjaxhtml: show_clusters_DIVlist:: \t'. $ex->getMessage(). "\n");
                        echo "400";
                    }
                    break;
                    
                case "show_clusters_drp": //like                
                    try {
                    //getClusters
                        $oDropfilters= new CGetFilters();
                        $clusterDrops=$oDropfilters->getClusters($loggedInId,1);
                        $clusterListStr='';
                        $clusterStr='
                            <select id="{0}"  name="{0}" {2}>
                                <option value="" selected="selected">{1}</option>';
                                foreach($clusterDrops as $mycluster){
                                    $clusterStr.='<option value="'.$mycluster["Cluster_ID"].'" >'.$mycluster["Cluster_Name"].'</option>';
                                    $clusterListStr.='<li><a onclick="showMyClusters('.$mycluster["Cluster_ID"].');">'.$mycluster["Cluster_Name"].'</a></li>';
                                }
                            $clusterStr.='</select>';
                        echo $clusterStr."[SEP]".$clusterListStr;
                    }
                    catch(Exception $ex){
                        $oLog->writeException('ajax/getAjaxhtml: getClusters():: \t'. $ex->getMessage(). "\n");
                        echo "400";
                    }
                    break;
                    
                case "show_clusters_DIVlist": //like                
                    try {
                    //getClusters
                        $oDropfilters= new CGetFilters();
                        $clusterDrops=$oDropfilters->getClusters($loggedInId,1);
                        
                        
                        $clusterStr='';
                                foreach($clusterDrops as $mycluster){
                                    $clusterStr.='<li><a onclick="showMyClusters('.$mycluster["Cluster_ID"].',this.innerHTML);">'.$mycluster["Cluster_Name"].'</a></li>';
                                }
                        echo $clusterStr;
                    }
                    catch(Exception $ex){
                        $oLog->writeException('ajax/getAjaxhtml: show_clusters_DIVlist:: \t'. $ex->getMessage(). "\n");
                        echo "400";
                    }
                    break;
                    
                case "show_post_report_abused": //post abused report types                
                    try {
                    //getClusters
                        $oDropfilters= new CGetFilters();
                        $reportabuseDrops=$oDropfilters->getReportAbuseTypes($loggedInId,1);
                        $postid=0;
                    	if (isset($_POST["report_abused_post_id"]) && !empty($_POST["report_abused_post_id"])) {
			                $postid = trim($_POST["report_abused_post_id"]);
			            }
			           //echo "uid: ".$loggedInId." postid: ".$postid;
                        $postReportAbused=$oDropfilters->getPostReportAbuseTypes($loggedInId,$postid);
                        if(is_array($postReportAbused)){
                            $postReportAbused=$postReportAbused[0];
                        }
                       //echo "<pre>";
                        //print_r($postReportAbused);
                        //echo "</pre>";
                        //die();
                        $report_abusedStr='<div id="light_edit_post_settings_'.$postid.'" style="display:none"><table>
                                    <tr>
                                        <td>
                                            Report Abuse
                                                <div style="padding:10px;">
                                                    <div id="abuse_types_'.$postid.'">
                                                       <table>';
                                        $isReported=false;
                                        foreach($reportabuseDrops as $reporttype){
                                            
                                            if(isset($postReportAbused["Status"])){
                                                if(strstr($postReportAbused["Report_Abuse_IDs"],",")){
                                                    $postReportedAbusedArr=explode(",",$postReportAbused["Report_Abuse_IDs"]);
                                                    if(in_array($reporttype["ID"],$postReportedAbusedArr)){
                                                        $isReported=true;
                                                    }
                                                    else{
                                                        $isReported=false;
                                                    }
                                                }
                                                else{
                                                    if(is_numeric($postReportAbused["Report_Abuse_IDs"]) &&  $reporttype["ID"]==$postReportAbused["Report_Abuse_IDs"]){
                                                        $isReported=true;
                                                    }
                                                    else
                                                        $isReported=false;
                                                }
                                            }
                                            else{                                                
                                                $isReported=false;
                                            }
                                            
                                            $ischeckedStr="";
                                            $isStatuscheckedStr=""; 
                                            $strStatus="Show";
                                            if(isset($postReportAbused["Status"])){
                                                if( $postReportAbused["Status"]==1){
                                                    $strStatus="Hide";
                                                }
                                                if($postReportAbused["Status"]==1){
                                                    $isStatuscheckedStr="checked='true'";
                                                }
                                                if($isReported==true){
                                                    $ischeckedStr="checked='true'";
                                                }
                                            }
                                            else{
                                                $strStatus="Hide";
                                                $isStatuscheckedStr="checked='true'";
                                            }
                                            
                                            
                                            $report_abusedStr.='<tr>
                                                            <td>'.$reporttype["Report_Abuse_Type"].'</td>
                                                            <td>
                                                                <input type="checkbox" id="chk_'.$postid.'_'.$reporttype["ID"].'" name="chk_'.$postid.'_'.$reporttype["ID"].'" class="rpt_'.$postid.'" onclick="return findAllCheckedReportType('.'\'rpt_'.$postid.'\',\''.$reporttype["ID"].'\');" '.$ischeckedStr.'  />
                                                            </td>
                                                          </tr>';
                                        }                                                    
                                        $chkPostHideId="hid_rpt_".$postid;
                                        
                                $report_abusedStr.='   </table>
                                                    </div>
                                                </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <a href="javascript:void(0);" onclick="return reportThisPost(\''.$chkPostHideId.'\');" id="isPostHide_'.$postid.'">'.$strStatus.'</a>
                                        </td>
                                    </tr>
                                    <!--
                                    <tr>
                                        <td>
                                            Add location
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            Full Screen
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            Download
                                        </td>
                                    </tr>
                                    
                                    <tr>
                                        <td>
                                            Enclosed
                                            <div>--</div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            Enclose
                                            <div>
                                                <input type="text"/>
                                            </div>
                                            
                                        </td>
                                    </tr>
                                    -->
                                    <tr>
                                        <td>
                                            <div style="display:none">
                                                <input type="checkbox" id="hid_rpt_'.$postid.'" name="hid_rpt_'.$postid.'" '.$isStatuscheckedStr.' />
                                            </div>
                                            <input type="button" onclick="savePostSettings('.$postid.');" value="Finish" />                                            
                                        </td>
                                    </tr>
                                </table>
                                </div>';
                                
                        echo $report_abusedStr;
                    }
                    catch(Exception $ex){
                        $oLog->writeException('ajax/getAjaxhtml: getReportAbuseTypes():: \t'. $ex->getMessage(). "\n");
                        echo "400";
                    }
                    break;
            }
        }
        else{
            echo "-999";
        }
    
    }
    catch(Exception $ex){
        echo "500"; 
    } 
}
?>